import 'package:flutter/material.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

import '../../../hj_model/video_model.dart';
import '../../../routers/jump_router.dart';
import '../../../tools_base/widget/net_image_widget.dart';

class VideoHorCellWidget extends StatelessWidget {
  final VideoModel? videoModel;
  final GestureTapCallback? onTap;
  final double imageWidth;
  const VideoHorCellWidget({
    super.key,
    this.videoModel,
    this.onTap,
    this.imageWidth = 160,
  });

  @override
  Widget build(BuildContext context) {
    String tagDesc = "";
    for(TagsBean tagModel in (videoModel?.tags ?? [])){
      tagDesc += "#${tagModel.name}  ";
    }
    return GestureDetector(
      onTap: onTap ??
          () {
            if (videoModel?.isRandomAd() == true) {
              pushToPageByLink(videoModel?.randomAdsInfo?.href, id: videoModel?.randomAdsInfo?.id);
              return;
            } else {
              pushToVideoPage(videoModel: videoModel);
            }
          },
      child: Row(
        children: [
          NetworkImageLoader(
            width: imageWidth,
            height: double.infinity,
            borderRadius: 4,
            imageUrl: videoModel?.cover ?? "",
          ),
          10.sizeBoxW,
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Text(
                  "${videoModel?.title ?? ""}\n",
                  maxLines: 2,
                  style: TextStyle(
                    color: Color(0xE5FFFFFF),
                    fontSize: 12,
                    height: 1.2,
                    fontWeight: FontWeight.w400,
                  ),
                  overflow: TextOverflow.ellipsis,
                ),
                Text(
                  "$tagDesc",
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    color: Color(0x8CFFFFFF),
                    fontSize: 12,
                  ),
                ),
                Text(
                  "播放${videoModel?.playCount?.humanizeFormat ?? "0"}",
                  maxLines: 2,
                  style: TextStyle(
                    color: Color(0x8CFFFFFF),
                    fontSize: 12,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _createTagItem(TagsBean tagItem) {
    return GestureDetector(
      child: Container(
        color: Colors.transparent,
        child: Text(
          "${tagItem.name ?? ""}",
          style: TextStyle(
            color: Color(0xffA7A7A7),
            fontSize: 10,
          ),
        ),
      ),
    );
  }

  Widget _buildPriceItem() {
    if (videoModel?.freeArea == true) {
      return Container(
        padding: EdgeInsets.symmetric(horizontal: 6, vertical: 3),
        decoration: BoxDecoration(
          color: Color(0xffFF6767),
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(8),
            bottomRight: Radius.circular(8),
          ),
        ),
        child: Text(
          "免费",
          style: TextStyle(
            color: Colors.white,
            fontSize: 10,
          ),
        ),
      );
    }
    if ((videoModel?.originCoins ?? 0) > 0) {
      return Container(
        padding: EdgeInsets.symmetric(horizontal: 6, vertical: 3),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(8),
            bottomRight: Radius.circular(8),
          ),
          gradient: LinearGradient(
            colors: [
              Color(0xff74B9D7),
              Color(0xff3733FF),
            ],
          ),
        ),
        child: Text(
          "${videoModel?.originCoins}金币",
          style: TextStyle(
            color: Colors.white,
            fontSize: 10,
          ),
        ),
      );
    }
    return SizedBox();
  }
}
